Class pyglet.graphics.Batch

Manage a collection of vertex lists for batched rendering.

Vertex lists are added to a Batch using the add and add_indexed methods. An optional group can be specified along with the vertex list, which gives the OpenGL state required for its rendering. Vertex lists with shared mode and group are allocated into adjacent areas of memory and sent to the graphics card in a single operation.

Call VertexList.delete to remove a vertex list from the batch.

Methods

  __init__(self)
Create a graphics batch.
VertexList add(self, count, mode, group, *data)
Add a vertex list to the batch.
IndexedVertexList add_indexed(self, count, mode, group, indices, *data)
Add an indexed vertex list to the batch.
  migrate(self, vertex_list, mode, group, batch)
Migrate a vertex list to another batch and/or group.
  draw(self)
Draw the batch.
  draw_subset(self, vertex_lists)
Draw only some vertex lists in the batch.

Method Details

add

add(self, count, mode, group, *data)
Add a vertex list to the batch.
Parameters:
count : int
The number of vertices in the list.
mode : int
OpenGL drawing mode enumeration; for example, one of GL_POINTS, GL_LINES, GL_TRIANGLES, etc. See the module summary for additional information.
group : Group
Group of the vertex list, or None if no group is required.
data : data items
Attribute formats and initial data for the vertex list. See the module summary for details.
Returns: VertexList

add_indexed

add_indexed(self, count, mode, group, indices, *data)
Add an indexed vertex list to the batch.
Parameters:
count : int
The number of vertices in the list.
mode : int
OpenGL drawing mode enumeration; for example, one of GL_POINTS, GL_LINES, GL_TRIANGLES, etc. See the module summary for additional information.
group : Group
Group of the vertex list, or None if no group is required.
indices : sequence
Sequence of integers giving indices into the vertex list.
data : data items
Attribute formats and initial data for the vertex list. See the module summary for details.
Returns: IndexedVertexList

migrate

migrate(self, vertex_list, mode, group, batch)

Migrate a vertex list to another batch and/or group.

vertex_list and mode together identify the vertex list to migrate. group and batch are new owners of the vertex list after migration.

The results are undefined if mode is not correct or if vertex_list does not belong to this batch (they are not checked and will not necessarily throw an exception immediately).

batch can remain unchanged if only a group change is desired.

Parameters:
vertex_list : VertexList
A vertex list currently belonging to this batch.
mode : int
The current GL drawing mode of the vertex list.
group : Group
The new group to migrate to.
batch : Batch
The batch to migrate to (or the current batch).

draw_subset

draw_subset(self, vertex_lists)

Draw only some vertex lists in the batch.

The use of this method is highly discouraged, as it is quite inefficient. Usually an application can be redesigned so that batches can always be drawn in their entirety, using draw.

The given vertex lists must belong to this batch; behaviour is undefined if this condition is not met.

Parameters:
vertex_lists : sequence of VertexList or IndexedVertexList
Vertex lists to draw.